# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=pandoc-plot
pkgver=1.6.2
pkgrel=7
pkgdesc="A Pandoc filter to include figures generated from code blocks using your plotting toolkit of choice."
url="https://github.com/LaurentRDC/pandoc-plot#readme"
license=("GPL")
arch=('loong64' 'x86_64')
depends=('ghc-libs' 'haskell-aeson' 'haskell-data-default' 'haskell-gitrev' 'haskell-hashable'
         'haskell-lifted-async' 'haskell-lifted-base' 'haskell-optparse-applicative'
         'haskell-pandoc' 'haskell-pandoc-types' 'haskell-shakespeare' 'haskell-tagsoup'
         'haskell-typed-process' 'haskell-yaml')
makedepends=('ghc' 'haskell-hspec-expectations' 'haskell-tasty' 'haskell-tasty-hspec'
             'haskell-tasty-hunit')
source=("https://hackage.haskell.org/packages/archive/$pkgname/$pkgver/$pkgname-$pkgver.tar.gz")
sha256sums=('ca53fb5435032b7d367014eeda957ab622ab2a4e164b38db5a98d260ab1e348b')

build() {
  cd $pkgname-$pkgver

  runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
    --prefix=/usr --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname --enable-tests \
    --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid --ghc-option=-fllvm \
    --ghc-option=-optl-Wl\,-z\,relro\,-z\,now \
    --ghc-option='-pie' 

  runhaskell Setup build $MAKEFLAGS
  runhaskell Setup register --gen-script
  runhaskell Setup unregister --gen-script
  sed -i -r -e "s|ghc-pkg.*update[^ ]* |&'--force' |" register.sh
  sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

check() {
  cd $pkgname-$pkgver
  runhaskell Setup test --show-details=direct
}

package() {
  cd $pkgname-$pkgver

  install -D -m744 register.sh "$pkgdir"/usr/share/haskell/register/$pkgname.sh
  install -D -m744 unregister.sh "$pkgdir"/usr/share/haskell/unregister/$pkgname.sh
  runhaskell Setup copy --destdir="$pkgdir"
  install -D -m644 LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname/
  rm -f "$pkgdir"/usr/share/doc/$pkgname/LICENSE
}
